;************************************************************************************************************************
;myupdate.iss by eljorgejones 20100310a
;************************************************************************************************************************

variable string MYUPDATECONFIGPATH="${LavishScript.HomeDirectory}/Scripts/EQ/Config"
variable string MYUPDATEUIPATH="${LavishScript.HomeDirectory}/Scripts/EQ/UI"
variable string MYUPDATESCRIPTPATH="${LavishScript.HomeDirectory}/Scripts/EQ"
variable string WINDOWELEMENT=deployui
variable string TABCONTROLELEMENT=deploytab
variable string sdeploy
variable string sversion
variable string ssbversion
variable string cversion
variable string sfilename1
variable string sfilename2
variable string sfilename3
variable string sfilename4
variable string sfilename5
variable string sfilename6
variable string sfilename7
variable string sfilename8
variable string sfilename9
variable string sfilename10
variable string sfilename11
variable string sfilename12
variable string sfilename13
variable string sfilename14
variable string sfilename15
variable string sfilename16
variable string sfilename17
variable string sfilename18
variable string sfilename19
variable string sfilename20
variable string lfilename1
variable string lfilename2
variable string lfilename3
variable string lfilename4
variable string lfilename5
variable string lfilename6
variable string lfilename7
variable string lfilename8
variable string lfilename9
variable string lfilename10
variable string lfilename11
variable string lfilename12
variable string lfilename13
variable string lfilename14
variable string lfilename15
variable string lfilename16
variable string lfilename17
variable string lfilename18
variable string lfilename19
variable string lfilename20

variable settingsetref supdate

function main(string myversion, string myversion2)
{
	ui -reload "${MYUPDATEUIPATH}/deploy.xml"
	UIElement[${WINDOWELEMENT}].FindChild[${TABCONTROLELEMENT}].FindChild[Update].FindChild[xmlcversion]:SetText[My EQ Hotbuttons version:${myversion}]
	UIElement[${WINDOWELEMENT}].FindChild[${TABCONTROLELEMENT}].FindChild[Update].FindChild[xmlcsbversion]:SetText[My Shitbuilder Version:${myversion2}]	
	sdeploy:Set[http://dl.dropbox.com/u/4241804/Release/UI/updateconfig.xml]		

	do
	{
		if !${QueuedCommands}
		WaitFrame
	    else
		ExecuteQueued
	}
	while 1
}

function UpdateSettings()
{
	LavishSettings:AddSet[Updates]
	LavishSettings[Updates]:Clear
	LavishSettings[Updates]:AddSet[Update]
	supdate:Set[${LavishSettings[Updates].FindSet[Update]}]
	LavishSettings[Updates]:Import["${MYUPDATECONFIGPATH}/updateconfig.xml"]
		
	sversion:Set[${supdate.FindSetting[sversion,Check for Updates]}]
	ssbversion:Set[${supdate.FindSetting[ssbversion,]}]
	sfilename1:Set[${supdate.FindSetting[sfilename1,]}]
	sfilename2:Set[${supdate.FindSetting[sfilename2,]}]
	sfilename3:Set[${supdate.FindSetting[sfilename3,]}]
	sfilename4:Set[${supdate.FindSetting[sfilename4,]}]
	sfilename5:Set[${supdate.FindSetting[sfilename5,]}]
	sfilename6:Set[${supdate.FindSetting[sfilename6,]}]
	sfilename7:Set[${supdate.FindSetting[sfilename7,]}]
	sfilename8:Set[${supdate.FindSetting[sfilename8,]}]
	sfilename9:Set[${supdate.FindSetting[sfilename9,]}]
	sfilename10:Set[${supdate.FindSetting[sfilename10,]}]
	sfilename11:Set[${supdate.FindSetting[sfilename11,]}]
	sfilename12:Set[${supdate.FindSetting[sfilename12,]}]
	sfilename13:Set[${supdate.FindSetting[sfilename13,]}]
	sfilename14:Set[${supdate.FindSetting[sfilename14,]}]
	sfilename15:Set[${supdate.FindSetting[sfilename15,]}]
	sfilename16:Set[${supdate.FindSetting[sfilename16,]}]
	sfilename17:Set[${supdate.FindSetting[sfilename17,]}]
	sfilename18:Set[${supdate.FindSetting[sfilename18,]}]
	sfilename19:Set[${supdate.FindSetting[sfilename19,]}]
	sfilename20:Set[${supdate.FindSetting[sfilename20,]}]
	lfilename1:Set[${supdate.FindSetting[lfilename1,]}]
	lfilename2:Set[${supdate.FindSetting[lfilename2,]}]
	lfilename3:Set[${supdate.FindSetting[lfilename3,]}]
	lfilename4:Set[${supdate.FindSetting[lfilename4,]}]
	lfilename5:Set[${supdate.FindSetting[lfilename5,]}]
	lfilename6:Set[${supdate.FindSetting[lfilename6,]}]
	lfilename7:Set[${supdate.FindSetting[lfilename7,]}]
	lfilename8:Set[${supdate.FindSetting[lfilename8,]}]
	lfilename9:Set[${supdate.FindSetting[lfilename9,]}]
	lfilename10:Set[${supdate.FindSetting[lfilename10,]}]
	lfilename11:Set[${supdate.FindSetting[lfilename11,]}]
	lfilename12:Set[${supdate.FindSetting[lfilename12,]}]
	lfilename13:Set[${supdate.FindSetting[lfilename13,]}]
	lfilename14:Set[${supdate.FindSetting[lfilename14,]}]
	lfilename15:Set[${supdate.FindSetting[lfilename15,]}]
	lfilename16:Set[${supdate.FindSetting[lfilename16,]}]
	lfilename17:Set[${supdate.FindSetting[lfilename17,]}]
	lfilename18:Set[${supdate.FindSetting[lfilename18,]}]
	lfilename19:Set[${supdate.FindSetting[lfilename19,]}]
	lfilename20:Set[${supdate.FindSetting[lfilename20,]}]
	
	UIElement[${WINDOWELEMENT}].FindChild[${TABCONTROLELEMENT}].FindChild[Update].FindChild[xmlsversion]:SetText[EQ Hotbuttons Server Version:${sversion}]		
	UIElement[${WINDOWELEMENT}].FindChild[${TABCONTROLELEMENT}].FindChild[Update].FindChild[xmlssbversion]:SetText[Shitbuilder Server Version:${ssbversion}]		
}

function downloadcheck()
{
	Execute httpget -file "./Config/updateconfig.xml" ${sdeploy}
	wait 40
	echo Loading Settings contained in updateconfig.xml!
	call UpdateSettings
}

function startitup()
{
	run eqisbuttons.iss
	wait 40
	call atexit
}
function startshitbuilder()
{
	run shitbuilder.iss
	wait 40
	call atexit
}
function deployupdate()
{
	MessageBox "This will backup and download the latest files from the server. Check console for update messages and any errors (default console key is ~}.  Click OK to continue!" 
	echo Backing up files!
	ISBoxerUI:PopupText["Backing up files",5000]
	cp -overwrite "./eqisbuttons.iss" "./eqisbuttons.mybak"
	wait 10
	cp -overwrite "./eqbuttonslib.iss" "./eqbuttonslib.mybak"
	wait 10
	cp -overwrite "./myupdate.iss" "./myupdate.mybak"
	wait 10
	cp -overwrite "./UI/eqisbuttons.xml" "./UI/eqisbuttons.mybak"
	wait 10
	cp -overwrite "./UI/eqisbuttonsls.xml" "./UI/eqisbuttonsls.mybak"
	wait 10
	cp -overwrite "./UI/tab1.xml" "./UI/tab1.mybak"
	wait 10
	cp -overwrite "./UI/tab2.xml" "./UI/tab2.mybak"
	wait 10
	cp -overwrite "./UI/tab1ls.xml" "./UI/tab1ls.mybak"
	wait 10
	cp -overwrite "./UI/tab2ls.xml" "./UI/tab2ls.mybak"
	wait 10
	cp -overwrite "./UI/xmluisettings.xml" "./UI/xmluisettings.mybak"
	wait 10
	cp -overwrite "./UI/gxmluisettings.xml" "./UI/gxmluisettings.mybak"
	wait 10
	cp -overwrite "./UI/eqisghost1.xml" "./UI/eqisghost1.mybak"
	wait 10
	cp -overwrite "./UI/eqisghost2.xml" "./UI/eqisghost2.mybak"
	wait 10
	cp -overwrite "./UI/eqisbuttonsg.xml" "./UI/eqisbuttonsg.mybak"
	wait 10
	cp -overwrite "./UI/shitbuilder.xml" "./UI/shitbuilder.mybak"
	wait 10
	cp -overwrite "./shitbuilder.iss" "./shitbuilder.mybak"
	wait 10
	
	echo Downloading new files!
	ISBoxerUI:PopupText["Download starting",5000]
	httpget -file "./${lfilename1}" ${sfilename1} (exists)
	httpget -file "./${lfilename2}" ${sfilename2}
	httpget -file "./${lfilename3}" ${sfilename3}
	httpget -file "./UI/${lfilename4}" ${sfilename4}
	httpget -file "./UI/${lfilename5}" ${sfilename5}
	httpget -file "./UI/${lfilename6}" ${sfilename6}
	httpget -file "./UI/${lfilename7}" ${sfilename7}
	httpget -file "./UI/${lfilename8}" ${sfilename8}
	httpget -file "./UI/${lfilename9}" ${sfilename9}
	httpget -file "./UI/${lfilename10}" ${sfilename10}
	httpget -file "./UI/${lfilename11}" ${sfilename11}
	httpget -file "./UI/${lfilename12}" ${sfilename12}
	httpget -file "./UI/${lfilename13}" ${sfilename13}
	httpget -file "./UI/${lfilename14}" ${sfilename14}
	httpget -file "./UI/${lfilename15}" ${sfilename15}
	httpget -file "./UI/${lfilename16}" ${sfilename16}
	httpget -file "./UI/${lfilename17}" ${sfilename17}
	httpget -file "./UI/${lfilename18}" ${sfilename18}
	httpget -file "./${lfilename19}" ${sfilename19}
	wait 200
	echo Update complete
	ISBoxerUI:PopupText["Update Is Complete",5000]
	MessageBox "Backup should be complete. Check console for update messages and any errors (default console key is ~}.  Click OK to continue!" 
}

function rollbackupdate()
{
	MessageBox "This will rollback EQ Hotbuttons to your previous running version. Check console for update messages and any errors (default console key is ~}.  Click OK to continue!" 
	echo Restoring files!
	ISBoxerUI:PopupText["Rolling back files",5000]
	cp -overwrite "./eqisbuttons.mybak" "./eqisbuttons.iss"
	wait 10
	cp -overwrite "./eqbuttonslib.mybak" "./eqbuttonslib.iss"
	wait 10
	cp -overwrite "./myupdate.mybak" "./myupdate.iss"
	wait 10
	cp -overwrite "./UI/eqisbuttons.mybak" "./UI/eqisbuttons.xml"
	wait 10
	cp -overwrite "./UI/eqisbuttonsls.mybak" "./UI/eqisbuttonsls.xml"
	wait 10
	cp -overwrite "./UI/tab1.mybak" "./UI/tab1.xml"
	wait 10
	cp -overwrite "./UI/tab2.mybak" "./UI/tab2.xml"
	wait 10
	cp -overwrite "./UI/tab1ls.mybak" "./UI/tab1ls.xml"
	wait 10
	cp -overwrite "./UI/tab2ls.mybak" "./UI/tab2ls.xml"
	wait 10
	cp -overwrite "./UI/xmluisettings.mybak" "./UI/xmluisettings.xml"
	wait 10
	cp -overwrite "./UI/gxmluisettings.mybak" "./UI/gxmluisettings.xml"
	wait 10
	cp -overwrite "./UI/eqisghost1.mybak" "./UI/eqisghost1.xml"
	wait 10
	cp -overwrite "./UI/eqisghost2.mybak" "./UI/eqisghost2.xml"
	wait 10
	cp -overwrite "./UI/eqisbuttonsg.mybak" "./UI/eqisbuttonsg.xml"
	wait 200
	cp -overwrite "./UI/shitbuilder.mybak" "./UI/shitbuilder.xml"
	wait 200
	cp -overwrite "./shitbuilder.mybak" "./shitbuilder.iss"
	wait 200
	echo Rollback complete!
	ISBoxerUI:PopupText["Rollback Is Complete",5000]
	MessageBox "Rollback should be complete. Check console for messages and any errors (default console key is ~}.  Click OK to continue!" 
}

function atexit()
{
	ui -unload "${MYUPDATEUIPATH}/deploy.xml"
}